#include <stdio.h>
#include <omp.h>
//编译指令
//gcc -std=c99 -fopenmp 6Critical.c -o cmake-build/6Critical && export OMP_NUM_THREADS=512 && time ./cmake-build/6Critical
int main()
{
    int tid,i=0,sum=0,SUM=0;
    int a[4];
    for(i=0;i<4;i++)
        a[i]=i;
    #pragma omp parallel num_threads(4) private(i,tid) firstprivate(sum) shared(SUM) shared(a) default(none)
    {
        tid=omp_get_thread_num();
        #pragma omp for
        for(i=0;i<4;++i)
            sum+=a[i];
        #pragma omp critical
        {
            SUM+=sum;
            printf("Thread %d:sum=%d SUM=%d\n",tid,sum,SUM);
        }
    }

}
